home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ov143b.zip / DIRECT.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  21KB  |  710 lines

  1.         PAGE   60,132
  2.         TITLE  Routines to do direct screen I/O
  3.  
  4. ;  012  18-Apr-87  direct.asm
  5.  
  6. ;       Copyright (c) 1986,1987 by Blue Sky Software.  All rights reserved.
  7.  
  8. ;****************************************************************************
  9. ;****** Make sure the following symbol matches calling program usage ********
  10. ;****************************************************************************
  11.  
  12. ALTCALL EQU    'pascal'        ; Uses alternate calling sequence when defined
  13.  
  14. ;****************************************************************************
  15.  
  16. B_proc  MACRO  lname,uname             ; simple Begin proc macro
  17. IFDEF   ALTCALL
  18.         PUBLIC uname
  19. uname   PROC   NEAR
  20. ELSE
  21.         PUBLIC lname
  22. lname   PROC   NEAR
  23. ENDIF
  24.         ENDM
  25.  
  26. E_proc  MACRO  lname,uname,n           ; simple End proc macro
  27. IFDEF   ALTCALL
  28.         ret    n
  29. uname   ENDP
  30. ELSE
  31.         ret
  32. lname   ENDP
  33. ENDIF
  34.         ENDM
  35.  
  36. Param   MACRO  sym,cway,pway           ; simple parameter defination macro
  37. IFDEF   ALTCALL
  38. sym     EQU    [bp+pway]
  39. ELSE
  40. sym     EQU    [bp+cway]
  41. ENDIF
  42.         ENDM
  43.  
  44. _TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  45. _TEXT   ENDS
  46. CONST   SEGMENT  WORD PUBLIC 'CONST'
  47. CONST   ENDS
  48. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  49. _BSS    ENDS
  50. _DATA   SEGMENT  WORD PUBLIC 'DATA'
  51. _DATA   ENDS
  52.  
  53. DGROUP  GROUP   CONST,  _BSS,   _DATA
  54.         ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  55.  
  56. _DATA   SEGMENT
  57.         EXTRN   _screen:DWORD
  58.         EXTRN   _cursor:DWORD
  59.         EXTRN   _vid_attrib:BYTE
  60.         EXTRN   _vid_snow:BYTE
  61.         boxloc  dw    0           ; stores the starting offset to the dialog box
  62. _DATA   ENDS
  63.  
  64. _TEXT      SEGMENT
  65.  
  66. ;******************************************************************************
  67. ;
  68. ;  gotorc(row,col)    move 'cursor' to specified row, col
  69. ;
  70. ;******************************************************************************
  71.  
  72.         B_proc _gotorc,GOTORC
  73.  
  74.         Param  Row,4,6
  75.         Param  Col,6,4
  76.  
  77.         push    bp
  78.         mov     bp,sp
  79.  
  80.         mov     ax,Row                         ; row to ax
  81.         mov     cl,5
  82.         shl     ax,cl                          ; row * 32
  83.         mov     bx,ax
  84.         shl     ax,1
  85.         shl     ax,1                           ; row * 128
  86.         add     ax,bx                          ; row * 160
  87.  
  88.         mov     bx,Col                         ; col to bx
  89.         shl     bx,1                           ; col * 2
  90.  
  91.         add     ax,bx                          ; row * 160 + col * 2 = cursor
  92.         mov     WORD PTR _cursor,ax
  93.  
  94.         mov     sp,bp
  95.         pop     bp
  96.  
  97.         E_proc  _gotorc,GOTORC,4
  98.  
  99. ;******************************************************************************
  100. ;
  101. ;  disp_str(s)    display a string at current location
  102. ;
  103. ;******************************************************************************
  104.  
  105.         B_proc _disp_str,DISP_STR
  106.  
  107.         push    bp
  108.         mov     bp,sp
  109.         push    di
  110.         push    si
  111.         mov     si,[bp+4]
  112.  
  113.         mov     ah,_vid_attrib         ; attribute byte to ah
  114.         les     di,DWORD PTR _cursor   ; cursor ptr to es:di
  115.  
  116.         jmp     SHORT tst_ch           ; skip to load/test code
  117.  
  118. chloop:
  119.  
  120.         IFDEF  nosnow                  ; if adapter doesn't snow, its quick
  121.            stosw                       ; store char and attrib to es:[di++]
  122.         ELSE                           ; well, its not so quick or easy....
  123.            mov    cx,1
  124.            call   stvideo
  125.         ENDIF
  126.  
  127. tst_ch: lodsb                          ; string char to al
  128.         or      al,al                  ; done when char = 0
  129.         jne     chloop
  130.  
  131.         mov     WORD PTR _cursor,di    ; update cursor offset
  132.  
  133.         pop     si
  134.         pop     di
  135.         mov     sp,bp
  136.         pop     bp
  137.  
  138.         E_proc _disp_str,DISP_STR,2
  139.  
  140. ;******************************************************************************
  141. ;
  142. ;   disp_char(ch)   display a single char at current location
  143. ;
  144. ;******************************************************************************
  145.  
  146.         B_proc _disp_char,DISP_CHAR
  147.  
  148.         push    bp
  149.         mov     bp,sp
  150.         push    di
  151.  
  152.         les     di,DWORD PTR _cursor   ; cursor loc to es:di
  153.  
  154.         mov     al,[bp+4]              ; get char to store in video memory
  155.         mov     ah,_vid_attrib         ; get video attribute
  156.  
  157.         IFDEF nosnow
  158.            stosw                       ; store 'em and update di
  159.         ELSE
  160.            mov  cx,1
  161.            call stvideo
  162.         ENDIF
  163.  
  164.         mov     WORD PTR _cursor,di    ; update cursor offset
  165.  
  166.         pop     di
  167.         mov     sp,bp
  168.         pop     bp
  169.  
  170.         E_proc _disp_char,DISP_CHAR,2
  171.  
  172.  
  173. ;******************************************************************************
  174. ;
  175. ;   disp_rep(ch,cnt)   display a single char cnt times at current location
  176. ;
  177. ;******************************************************************************
  178.  
  179.         B_proc _disp_rep,DISP_REP
  180.  
  181.         Param   Ch_d,4,6
  182.         Param   Cnt,6,4
  183.  
  184.         push    bp
  185.         mov     bp,sp
  186.         push    di
  187.  
  188.         les     di,DWORD PTR _cursor   ; cursor loc to es:di
  189.  
  190.         mov     al,Ch_d                ; get char to store in video memory
  191.         mov     ah,_vid_attrib         ; get video attribute
  192.         mov     cx,Cnt                 ; rep count to cx
  193.  
  194.         IFDEF  nosnow
  195.            rep stosw                   ; store 'em and update di
  196.         ELSE
  197.            call stvideo
  198.         ENDIF
  199.  
  200.         mov     WORD PTR _cursor,di    ; update cursor offset
  201.  
  202.         pop     di
  203.         mov     sp,bp
  204.         pop     bp
  205.  
  206.         E_proc _disp_rep,DISP_REP,4
  207.  
  208.  
  209. ;******************************************************************************
  210. ;
  211. ;       insert_line(row,n)   insert a line at row, effects n lines
  212. ;
  213. ;******************************************************************************
  214.  
  215.         Param   Row_l,4,6      ; Parameters for insert_line, delete_line,
  216.         Param   Num_l,6,4      ;    scroll_video
  217.  
  218.         B_proc _insert_line,INSERT_LINE
  219.  
  220.         push    bp
  221.         mov     bp,sp
  222.         push    di
  223.         push    si
  224.  
  225.         mov     bx,Row_l               ; ( r + n - 1) * 160 - 2 =
  226.         add     bx,Num_l               ;   end of new last row
  227.         dec     bx
  228.         mov     ax,160
  229.         imul    bx
  230.         dec     ax
  231.         dec     ax
  232.         mov     si,ax                  ;   (but its the source for the move)
  233.  
  234.         add     ax,160                 ; call addr of dest (where new last
  235.         mov     di,ax                  ;   line will go)
  236.  
  237.         std                            ; to insert a row, need to go backwards
  238.  
  239.         call    scroll_video           ; scroll the video buffer
  240.  
  241.         mov     al,20h                 ; fill the inserted line with blanks
  242.         mov     ah,_vid_attrib
  243.         mov     cx,80
  244.         IFDEF  nosnow
  245.            rep stosw
  246.         ELSE
  247.            call stvideo
  248.         ENDIF
  249.  
  250.         cld                            ; C expects it this way
  251.  
  252.         pop     si
  253.         pop     di
  254.         mov     sp,bp
  255.         pop     bp
  256.  
  257.         E_proc  _insert_line,INSERT_LINE,4
  258.  
  259.  
  260. ;******************************************************************************
  261. ;
  262. ;       delete_line(r,n)   delete a line at row, effects n lines
  263. ;
  264. ;******************************************************************************
  265.  
  266.         B_proc _delete_line,DELETE_LINE
  267.  
  268.         push    bp
  269.         mov     bp,sp
  270.         push    di
  271.         push    si
  272.  
  273.         mov     ax,160                 ; get row
  274.         imul    WORD PTR Row_l         ;   turn into offset in video ram
  275.         mov     di,ax
  276.  
  277.         add     ax,160                 ; calc offset of next row
  278.         mov     si,ax
  279.  
  280.         call    scroll_video           ; scroll the video buffer
  281.  
  282.         mov     al,20h                 ; fill the last line with blanks
  283.         mov     ah,_vid_attrib
  284.         mov     cx,80
  285.         IFDEF  nosnow
  286.            rep stosw
  287.         ELSE
  288.            call stvideo
  289.         ENDIF
  290.  
  291.         pop     si
  292.         pop     di
  293.         mov     sp,bp
  294.         pop     bp
  295.  
  296.         E_proc _delete_line,DELETE_LINE,4
  297.  
  298.  
  299. ;*****************************************************************************
  300. ;
  301. ;   scroll_video   support routine for insert/delete line
  302. ;
  303. ;*****************************************************************************
  304.  
  305. scroll_video PROC NEAR
  306.  
  307.         mov     ax,80                  ; get # rows to move and
  308.         imul    WORD PTR Num_l         ;   turn into # words to move
  309.         mov     cx,ax
  310.  
  311.         IFNDEF  nosnow
  312.            mov  al,_vid_snow           ; movideo needs vid_snow - get it
  313.         ENDIF                          ;   before ds gets changed
  314.  
  315.         push    ds                     ; save current ds
  316.         mov     bx,WORD PTR _screen+2  ; segment address of video ram
  317.         mov     ds,bx                  ; moving to/from video ram
  318.         mov     es,bx
  319.  
  320.         IFDEF   nosnow
  321.            rep movsw                   ; scroll the data in the video buffer
  322.         ELSE
  323.            call movideo
  324.         ENDIF
  325.  
  326.         pop    ds                      ; restore ds
  327.  
  328.         ret
  329.  
  330. scroll_video ENDP
  331.  
  332.  
  333. ;******************************************************************************
  334. ;
  335. ;       scrcpy(to,from)
  336. ;       char far *to, far *from;
  337. ;
  338. ;       copy screen image from to
  339. ;
  340. ;******************************************************************************
  341.  
  342.         B_proc _scrcpy,SCRCPY
  343.  
  344.         Param  To,4,8
  345.         Param  From,8,4
  346.  
  347.         push    bp
  348.         mov     bp,sp
  349.         push    di
  350.         push    si
  351.         push    ds
  352.  
  353.         IFNDEF  nosnow
  354.         mov     al,_vid_snow           ; flag for movideo
  355.         ENDIF
  356.  
  357.         les     di,To                  ; es:di is to address
  358.         lds     si,From                ; ds:si is from address
  359.         mov     cx,80*25               ; HARDCODED screen size in words
  360.  
  361.         IFDEF   nosnow                 ; move the screen image
  362.         rep movsw
  363.         ELSE
  364.         call    movideo
  365.         ENDIF
  366.  
  367.         pop     ds
  368.         pop     si
  369.         pop     di
  370.         mov     sp,bp
  371.         pop     bp
  372.  
  373.         E_proc _scrcpy,SCRCPY,8
  374.  
  375.  
  376. ;******************************************************************************
  377. ;
  378. ;       popup(row,col,nrows,ncols,savp)
  379. ;
  380. ;       pop up a dialog box on the screen starting at row,col.
  381. ;       If savp is not NULL, the current contents of the video ram
  382. ;       under the box are saved.
  383. ;
  384. ;******************************************************************************
  385.  
  386.         Param  Row_p,4,12      ; parameters for popup() & popdwn()
  387.         Param  Col_p,6,10
  388.         Param  Nrows,8,8
  389.         Param  Ncols,10,6
  390.         Param  Savp,12,4
  391.  
  392.         B_proc _popup,POPUP
  393.  
  394.         push    bp
  395.         mov     bp,sp
  396.         push    di
  397.         push    si
  398.  
  399.         mov     ax,160                         ; calc offset to start of
  400.         imul    WORD PTR Row_p                 ; dialog box -
  401.         mov     cx,Col_p                       ; row * 160 + (col << 1)
  402.         shl     cx,1
  403.         add     ax,cx
  404.  
  405.         mov     si,ax                          ; si now -> box start offset
  406.         mov     boxloc,si                      ; save it for later
  407.  
  408.         mov     di,Savp                        ; get savp, the save addr ptr
  409.         or      di,di                          ; does user want contents saved?
  410.         je      skipsave
  411.  
  412.         mov     dx,si                          ; save current row offset
  413.  
  414.         mov     bh, BYTE PTR Nrows             ; nrows to bh
  415.         mov     bl, BYTE PTR Ncols             ; ncols to bl
  416.  
  417.         mov     ax,ds                          ; set es and ds so str instrs
  418.         mov     es,ax                          ; work the way we want
  419.         mov     cx,WORD PTR _screen+2          ; ds points to video ram
  420.         mov     ds, cx
  421.  
  422.         IFNDEF  nosnow
  423.            mov  al,es: _vid_snow               ; movideo needs _vid_snow
  424.            push ax
  425.         ENDIF
  426.  
  427. nxtrow: mov     cl,bl                          ; move ncols to cx
  428.         xor     ch,ch
  429.  
  430.         IFDEF   nosnow
  431.            rep movsw                           ; move data
  432.         ELSE
  433.            pop  ax                             ; get/save _vid_snow
  434.            push ax
  435.            call movideo
  436.         ENDIF
  437.  
  438.         add     dx,160                         ; calc offset of next row
  439.         mov     si,dx
  440.  
  441.         dec     bh                             ; one more row done, any more?
  442.         jnz     nxtrow
  443.  
  444.         IFNDEF  nosnow
  445.            pop  ax                             ; clear stack
  446.         ENDIF
  447.  
  448.         mov     ax,es                          ; restore the ds reg
  449.         mov     ds,ax
  450.  
  451.         mov     si,boxloc                      ; reget box starting offset
  452.  
  453. skipsave:
  454.  
  455.         mov     di,si                          ; video ram is now the dest
  456.         mov     es,WORD PTR _screen+2          ; video ram segment
  457.  
  458.         mov     al,201                         ; disp the upper left corner
  459.         mov     ah,_vid_attrib                 ; the video attrib to use
  460.         IFDEF  nosnow
  461.            stosw                               ; store in video ram
  462.         ELSE
  463.            mov  cx,1
  464.            call stvideo
  465.         ENDIF
  466.  
  467.         mov     cx,Ncols                       ; now do the horizontal line
  468.         dec     cx                             ; its ncols - 2 long
  469.         dec     cx
  470.         mov     Ncols,cx                       ; ncols - 2 is used again
  471.         mov     al,205                         ; horizontal bar char
  472.         IFDEF   nosnow
  473.            rep stosw
  474.         ELSE
  475.            call stvideo
  476.         ENDIF
  477.  
  478.         mov     al,187                         ; disp the upper right corner
  479.         IFDEF   nosnow
  480.            stosw                               ; store in video ram
  481.         ELSE
  482.            mov  cx,1
  483.            call stvideo
  484.         ENDIF
  485.  
  486.         ; now do the blank lines in the body of the box
  487.  
  488.         mov     bx,Nrows                       ; the body is nrows - 2 long
  489.         dec     bx
  490.         dec     bx
  491.  
  492.         add     si,160                         ; bump row offset
  493.         mov     di,si
  494.  
  495. rownxt: mov     al,186                         ; do the left vertical bar
  496.         IFDEF   nosnow
  497.            stosw                               ; store in video ram
  498.         ELSE
  499.            mov  cx,1
  500.            call stvideo
  501.         ENDIF
  502.  
  503.         mov     cx,Ncols                       ; now all the blanks
  504.         mov     al,32
  505.         IFDEF   nosnow
  506.            rep stosw
  507.         ELSE
  508.            call stvideo
  509.         ENDIF
  510.  
  511.         mov     al,186                         ; do the right vertical bar
  512.         IFDEF   nosnow
  513.            stosw                               ; store in video ram
  514.         ELSE
  515.            mov  cx,1
  516.            call stvideo
  517.         ENDIF
  518.  
  519.         add     si,160                         ; bump row offset
  520.         mov     di,si
  521.  
  522.         dec     bx                             ; another row done
  523.         jnz     rownxt
  524.  
  525.         ; now do the bottom row of the box
  526.  
  527.         mov     al,200                         ; disp the lower left corner
  528.         IFDEF   nosnow
  529.            stosw                               ; store in video ram
  530.         ELSE
  531.            mov  cx,1
  532.            call stvideo
  533.         ENDIF
  534.  
  535.         mov     cx,Ncols                       ; now do the horizontal line
  536.         mov     al,205                         ; horizontal bar char
  537.         IFDEF   nosnow
  538.            rep stosw
  539.         ELSE
  540.            call stvideo
  541.         ENDIF
  542.  
  543.         mov     al,188                         ; disp the lower right corner
  544.         IFDEF   nosnow
  545.            stosw                               ; store in video ram
  546.         ELSE
  547.            mov  cx,1
  548.            call stvideo
  549.         ENDIF
  550.  
  551.         pop     si                             ; done, exit
  552.         pop     di
  553.         mov     sp,bp
  554.         pop     bp
  555.  
  556.         E_proc _popup,POPUP,10
  557.  
  558.  
  559. ;******************************************************************************
  560. ;
  561. ;       popdwn(row,col,nrows,ncols,savp)
  562. ;
  563. ;       Remove a pop up dialog box from the screen by restoring the prior
  564. ;       contents from savp.
  565. ;
  566. ;******************************************************************************
  567.  
  568.         B_proc _popdwn,POPDWN
  569.  
  570.         push    bp
  571.         mov     bp,sp
  572.         push    di
  573.         push    si
  574.  
  575.         mov     ax,160                         ; calc offset to start of
  576.         imul    WORD PTR Row_p                 ; dialog box -
  577.         mov     cx,Col_p                       ; row * 160 + (col << 1)
  578.         shl     cx,1
  579.         add     ax,cx
  580.  
  581.         mov     di,ax                          ; di now -> box start offset
  582.  
  583.         mov     si,Savp                        ; get savp, the save addr ptr
  584.  
  585.         mov     dx,di                          ; save current row offset
  586.  
  587.         mov     bh, BYTE PTR Nrows             ; nrows to bh
  588.         mov     bl, BYTE PTR Ncols             ; ncols to bl
  589.  
  590.         mov     es,WORD PTR _screen+2          ; oh yea, es points to video ram
  591.  
  592. next:   mov     cl,bl                          ; move ncols to cx
  593.         xor     ch,ch
  594.  
  595.         IFDEF  nosnow
  596.            rep movsw                           ; move data
  597.         ELSE
  598.            mov  al,_vid_snow
  599.            call movideo
  600.         ENDIF
  601.  
  602.         add     dx,160                         ; calc offset of next row
  603.         mov     di,dx
  604.  
  605.         dec     bh                             ; one more row done, any more?
  606.         jnz     next
  607.  
  608.         pop     si
  609.         pop     di
  610.         mov     sp,bp
  611.         pop     bp
  612.  
  613.         E_proc  _popdwn,POPDWN,10
  614.  
  615.         IFNDEF  nosnow
  616.  
  617. ;******************************************************************************
  618. ;
  619. ;   movideo - move data to/from video memory
  620. ;           - current video mode must be passed in al
  621. ;
  622. ;******************************************************************************
  623.  
  624. movideo PROC NEAR
  625.  
  626.         test    al,1                   ; do we need to check for snow?
  627.         jnz     goslow
  628.  
  629.         rep  movsw                     ; no snow, full speed ahead
  630.         ret                            ; that's all there is to it
  631.  
  632. goslow: push    dx                     ; it's a cga, go slow time
  633.  
  634.         mov     dx,03dah               ; dx = cga status port address
  635.  
  636. wait1:  in      al,dx                  ; get retrace status
  637.         test    al,8                   ; vertical retrace?
  638.         jnz     mov_it                 ; yes, go get the char
  639.         ror     al,1                   ; low bit set? (horizontal retrace)
  640.         jc      wait1                  ; current retrace may be almost done
  641.  
  642.         cli                            ; no interrupts until char loaded
  643.  
  644. wait2:  in      al,dx                  ; wait for start of next retrace
  645.         ror     al,1
  646.         jnc     wait2
  647.  
  648. mov_it: movsw                          ; move word to/from video ram
  649.  
  650.         sti                            ; allow interrupts
  651.  
  652.         loop    wait1                  ; all chars transfered?
  653.  
  654.         pop     dx                     ; restore dx
  655.  
  656.         ret
  657.  
  658. movideo ENDP
  659.  
  660.  
  661. ;******************************************************************************
  662. ;
  663. ;  stvideo - store the word in ax to video ram cx times
  664. ;
  665. ;******************************************************************************
  666.  
  667. stvideo PROC NEAR
  668.  
  669.         test    _vid_snow,1            ; do we need to slow for no snow?
  670.         jnz     slowgo
  671.  
  672.         rep  stosw                     ; no snow, full speed ahead
  673.         ret                            ; that's all there is to it
  674.  
  675. slowgo: push    bx                     ; snow, go slow
  676.         push    dx
  677.  
  678.         mov     dx,03dah               ; dx = cga status port address
  679.         mov     bx,ax
  680.  
  681. wait3:  in      al,dx                  ; get retrace status
  682.         test    al,8                   ; vertical retrace?
  683.         jnz     sto_it                 ; yes, go get the char
  684.         ror     al,1                   ; low bit set? (horizontal retrace)
  685.         jc      wait3                  ; current retrace may be almost done
  686.  
  687.         cli                            ; no interrupts until char loaded
  688.  
  689. wait4:  in      al,dx                  ; wait for start of next retrace
  690.         ror     al,1
  691.         jnc     wait4
  692.  
  693. sto_it: mov     ax,bx
  694.         stosw                          ; store word to video ram
  695.  
  696.         sti                            ; allow interrupts
  697.  
  698.         loop    wait3                  ; all chars transfered?
  699.  
  700.         pop     dx                     ; restore dx & bx
  701.         pop     bx
  702.  
  703.         ret
  704. stvideo ENDP
  705.  
  706.         ENDIF
  707.  
  708. _TEXT   ENDS
  709.         END
  710.